#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
typedef long long LL;
using namespace std;
const LL MAXN=3e7+7;
LL Res[MAXN];
void Init() {
	int a,b;
	for (int g=1; g<MAXN; ++g) {
		for (int j=1; 1ll*g*j<MAXN; ++j) {
			a=g*j;
			b=a^g;
			if (b==0) continue;
			if (a-b==g) ++Res[a];
		}
	}
	for (int i=1; i<MAXN; ++i) Res[i]+=Res[i-1];
}
int main(int argc, char** argv) {
	#ifdef hai
	freopen("in.txt", "r", stdin);
	#endif
	Init();
	int T;
	cin>>T;
	for (int cas=1; cas<=T; ++cas) {
		int ask;
		scanf("%d", &ask);
		printf("Case %d: %lld\n", cas, Res[ask]);
	}
	return 0;
} 
